
#include "ModulsManager\ClassAKRSmodul.h"



/****************************************************************************************************/
/*                           A K R S _ M O D U L E      C O N S T R U C T O R                         */
/****************************************************************************************************/
AKRSmodul::AKRSmodul(uint8_t devID, uint8_t modKey, AKRsData *pResult) : BASEmodul(devID,modKey)
{
  pData = pResult;
}


STATUS_MODUL AKRSmodul::ReadCHvals(void)
{
  STATUS_MODUL status;
  uint16_t val;
//
  status = RdMod(aUARTsets,8);
  if(status==ALL_RIGHT)
   { 
     val = BufToUSHT(0);
     pData->BaudRate = (AKRS_BAUD_RATE) (val&0xF);
     pData->UARTCtrl.ctrl = val&0xFFF0;
     pData->AKRSCtrl.ctrl = BufToCHAR(2);
     pData->TransDelay = BufToCHAR(3);
     pData->AnswTimeOut = BufToUSHT(4);
     pData->RqstTimeOut = BufToUSHT(6);
   }
//
  return status;
}



STATUS_MODUL AKRSmodul::SetUpModul(void)
{
  STATUS_MODUL status;
//
  status = ReadModInfo(MinModTypeAKRS);
  if(status==ALL_RIGHT)  status = SetUART();
  if(status==ALL_RIGHT)  status = SetDelays();
  if(status==ALL_RIGHT)  status =  WrKey();
//
  return status;
}


STATUS_MODUL AKRSmodul::SetUART(void)
{
  uint16_t val = pData->UARTCtrl.ctrl | pData->BaudRate;
  return WrMod(aUARTsets, 2, &val);
}


STATUS_MODUL AKRSmodul::SetAKRS(void)
{
  return WrMod(aAKRSst, 1, &pData->AKRSCtrl.ctrl);
}



STATUS_MODUL AKRSmodul::SetDelays(void)
{
  STATUS_MODUL status;
//
  status = WrMod(aDelayByte, 1, &pData->TransDelay);
  if(status==ALL_RIGHT)   status = WrMod(aDelayAnsw, 2, &pData->AnswTimeOut);
  if(status==ALL_RIGHT)   status = WrMod(aDelayReQuery, 2, &pData->RqstTimeOut);
//
  return status;
}
